/**
*┌──────────────────────────────────────────────────────────────┐
*│　描    述：User_point_log                                                    
*│　作    者：NetCoreCMS                                            
*│　版    本：1.0    模板代码自动生成                                                
*│　创建时间：2019-12-25 10:52:46                             
*└──────────────────────────────────────────────────────────────┘
*┌──────────────────────────────────────────────────────────────┐
*│　命名空间： NetCoreCMS.Services                                  
*│　类    名： User_point_logService                                    
*└──────────────────────────────────────────────────────────────┘
*/
using NetCoreCMS.IRepository;
using NetCoreCMS.IServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NetCoreCMS.Services
{
    public class User_point_logService: IUser_point_logService
    {
        private readonly IUser_point_logRepository _repository;
        private readonly IUsersRepository _users;
        private readonly IUser_groupsRepository _user_groups;
        private readonly IUser_amount_logService _user_amount_log;
        private readonly IUser_codeRepository _user_code;
        public User_point_logService(IUser_point_logRepository repository, IUsersRepository users, IUser_groupsRepository user_groups, IUser_amount_logService user_amount_log,IUser_codeRepository user_code)
        {
            _repository = repository;
            _users = users;
            _user_groups = user_groups;
            _user_amount_log = user_amount_log;
            _user_code = user_code;
        }

        public int Add(int user_id, string user_name, int value, string remark, bool is_upgrade)
        {
            Models.User_point_log model = new Models.User_point_log();
            model.user_id = user_id;
            model.user_name = user_name;
            model.value = value;
            model.remark = remark;
            int result = _repository.Add(model, is_upgrade);
            if (is_upgrade && value > 0 && result > 0)
            {
                new UsersService(_users, _user_groups, this, _user_amount_log,_user_code).Upgrade(user_id);
            }
            return result;
        }

        public bool Delete(int id)
        {
            return _repository.Delete(id) > 0;
        }

        public bool Delete(int id, string user_name)
        {
            return _repository.DeleteList("where id=@id and user_name=@user_name", new { id = id, user_name = user_name }) > 0;
        }

        public List<Models.User_point_log> GetList(int pageNumber, int rowsPerPage, string conditions, string orderby, object parameters = null)
        {
            return _repository.GetListPaged(pageNumber, rowsPerPage, conditions, orderby, parameters).ToList();
        }
        public int RecordCount(string conditions, object parameters = null)
        {
            return _repository.RecordCount(conditions, parameters);
        }
    }
}